import file


def is_account_exist(account):
    acc_dict = file.get_account_from_file()
    return account in acc_dict.keys()


def get_account_count():
    a_dict = file.get_account_from_file()
    return len(a_dict)


# 输入合法的密码1
def valid_password():
    while True:
        try:
            input_pw = input("请输入密码（6位数字）：")
            if len(input_pw) != 6:
                print("请输入六位数字！")
                break
            return int(input_pw)
        except ValueError:
            print("请不要输入其他字符！合法范围[0,9]的数字")


def option_input(option_list, divider, ljust_len):
    length = len(option_list)
    print(divider)
    for i, opt in enumerate(option_list, 1):
        print(f"* {i}. {opt}".ljust(ljust_len) + "*")
    print(divider)
    return valid_option_input(length)


def valid_option_input(length):
    while True:
        input_opt = input(f"* 请输入要操作的序号：[1至{length}]：")
        try:
            # 尝试将输入转换为整数
            number = int(input_opt)
            # 检查数字是否在合法范围内
            if 1 <= number <= length:
                return input_opt
            else:
                print("请输入合法范围的操作序号")
                continue
        except ValueError:
            # 如果输入无法转换为整数，返回False
            print("请输入整数")
            continue
